package com.solarroast.mirrorarray.gui.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.DefaultListModel;
import javax.swing.JList;

import com.solarroast.mirrorarray.beans.MAIBean;
import com.solarroast.mirrorarray.components.MirrorArray;
import com.solarroast.mirrorarray.components.MirrorArraySelection;

public class DeleteButtonListener implements ActionListener {
	private ArrayList<MirrorArraySelection> selections;
	private DefaultListModel model;
	private JList mirrorAreaList;
	
	public DeleteButtonListener(JList mirrorAreaList, ArrayList<MirrorArraySelection> selections, DefaultListModel model) {
		this.mirrorAreaList = mirrorAreaList;
		this.selections = selections;
		this.model = model;
	}

	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		if(mirrorAreaList.getSelectedIndex() < 0)
			System.out.println("Nothing selected");
		else {
			System.out.println("Deleting selection: " + model.get(mirrorAreaList.getSelectedIndex()));

			selections.remove(mirrorAreaList.getSelectedIndex());
			model.remove(mirrorAreaList.getSelectedIndex());
		}
	}
}
